# Copyright 2010-2025 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

### Arc Flow ###

cc_library(
    name = "arc_flow_builder",
    srcs = ["arc_flow_builder.cc"],
    hdrs = ["arc_flow_builder.h"],
    deps = [
        "//ortools/base",
        "//ortools/base:map_util",
        "//ortools/base:stl_util",
        "//ortools/graph:topologicalsorter",
        "@abseil-cpp//absl/container:flat_hash_map",
        "@abseil-cpp//absl/strings",
    ],
)

cc_library(
    name = "arc_flow_solver",
    srcs = [
        "arc_flow_solver.cc",
    ],
    hdrs = ["arc_flow_solver.h"],
    deps = [
        ":arc_flow_builder",
        "//ortools/base",
        "//ortools/base:file",
        "//ortools/linear_solver",
        "//ortools/packing:vector_bin_packing_cc_proto",
        "@abseil-cpp//absl/flags:flag",
    ],
)

### Vector Bin Packing ###

proto_library(
    name = "vector_bin_packing_proto",
    srcs = ["vector_bin_packing.proto"],
    visibility = ["//visibility:public"],
)

cc_proto_library(
    name = "vector_bin_packing_cc_proto",
    visibility = ["//visibility:public"],
    deps = [":vector_bin_packing_proto"],
)

cc_library(
    name = "vector_bin_packing_parser",
    srcs = ["vector_bin_packing_parser.cc"],
    hdrs = ["vector_bin_packing_parser.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":vector_bin_packing_cc_proto",
        "//ortools/base",
        "//ortools/util:filelineiter",
        "@abseil-cpp//absl/strings",
    ],
)

cc_binary(
    name = "vector_bin_packing",
    srcs = [
        "vector_bin_packing_main.cc",
    ],
    deps = [
        "//ortools/base",
        "//ortools/base:file",
        "//ortools/packing:arc_flow_builder",
        "//ortools/packing:arc_flow_solver",
        "//ortools/packing:vector_bin_packing_cc_proto",
        "//ortools/packing:vector_bin_packing_parser",
        "@abseil-cpp//absl/flags:flag",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/strings",
    ],
)

cc_test(
    name = "vector_bin_packing_test",
    size = "medium",
    srcs = [
        "vector_bin_packing_main.cc",
    ],
    args = ["--input $(rootpath //ortools/packing/testdata:1D__bpp_scholl__bin2data.N2W2B1R0.vbp)"],
    data = ["//ortools/packing/testdata:1D__bpp_scholl__bin2data.N2W2B1R0.vbp"],
    deps = [
        "//ortools/base",
        "//ortools/base:file",
        "//ortools/packing:arc_flow_builder",
        "//ortools/packing:arc_flow_solver",
        "//ortools/packing:vector_bin_packing_cc_proto",
        "//ortools/packing:vector_bin_packing_parser",
        "@abseil-cpp//absl/flags:flag",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/strings",
    ],
)

### Multiple Dimension (non vector) Bin Packing ###

proto_library(
    name = "multiple_dimensions_bin_packing_proto",
    srcs = ["multiple_dimensions_bin_packing.proto"],
    visibility = ["//visibility:public"],
)

cc_proto_library(
    name = "multiple_dimensions_bin_packing_cc_proto",
    visibility = ["//visibility:public"],
    deps = [":multiple_dimensions_bin_packing_proto"],
)

cc_library(
    name = "binpacking_2d_parser",
    srcs = ["binpacking_2d_parser.cc"],
    hdrs = ["binpacking_2d_parser.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":multiple_dimensions_bin_packing_cc_proto",
        "//ortools/base",
        "//ortools/util:filelineiter",
        "@abseil-cpp//absl/strings",
    ],
)
